package com.txsj.scan.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;

import com.txsj.scan.R;
import com.txsj.scan.adapter.EpcAdapter;
import com.txsj.scan.base.BaseActivity;
import com.txsj.scan.base.BasePresenter;
import com.txsj.scan.bean.EpcInfo;
import com.txsj.scan.utils.GsonFactory;
import com.txsj.scan.widget.TitleBarView;
import com.txsj.scan.widget.dialog.LabelIntroduceDialog;

import java.util.ArrayList;
import java.util.List;

public class UnTakeEpcLableActivity extends BaseActivity {

    @Override
    protected BasePresenter providePresenter() {
        return null;
    }

    private RecyclerView recyclerView;
    private EpcAdapter adapter;
    private List<EpcInfo> epcList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_unbind_label);
        initView();
        initData();
    }

    private void initData() {
        Intent intent = getIntent();
        String obj = intent.getStringExtra("data");
        String title = intent.getStringExtra("title");
        if (!TextUtils.isEmpty(obj)) {
            epcList = GsonFactory.getObjectList(obj, EpcInfo.class);
            adapter.setList(epcList);
            adapter.notifyDataSetChanged();
        }
        mTitle.setCenterText(title);
    }

    private void initView() {
        mTitle = (TitleBarView) findViewById(R.id.mTitle);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new EpcAdapter(this);
        recyclerView.setAdapter(adapter);
        mTitle.setRightOnclickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new LabelIntroduceDialog(UnTakeEpcLableActivity.this).show();
            }
        });
    }
}
